<?php


namespace plugin\colewechat\app\service;


use app\common\service\ConfigService;
use EasyWeChat\Factory;
use EasyWeChat\OfficialAccount\Application;
use support\exception\BadException;

class BaseService
{
    const COLEWECHAT_WECHATMP_CONFIG = "COLEWECHAT_WECHATMP_CONFIG";

    protected function getApp(): Application
    {
        $sysConfig = ConfigService::getConfig(self::COLEWECHAT_WECHATMP_CONFIG);
        if (!$sysConfig) {
            throw new BadException("请先配置公众号");
        }
        $config = [
            'app_id' => $sysConfig['app_id'],
            'secret' => $sysConfig['app_secret'],
        ];

        $app = Factory::officialAccount($config);
        return $app;
    }
}